/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package doan.quanlycanbo.portlet.service.impl;

import java.util.Date;
import java.util.List;

import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.ResourceConstants;

import doan.quanlycanbo.portlet.NoSuchdienbienhochamException;
import doan.quanlycanbo.portlet.NoSuchdienbienluongException;
import doan.quanlycanbo.portlet.NoSuchquatrinhdinuocngoaiException;
import doan.quanlycanbo.portlet.model.quatrinhdinuocngoai;
import doan.quanlycanbo.portlet.service.base.quatrinhdinuocngoaiLocalServiceBaseImpl;

/**
 * The implementation of the quatrinhdinuocngoai local service.
 *
 * <p>
 * All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link doan.quanlycanbo.portlet.service.quatrinhdinuocngoaiLocalService} interface.
 * </p>
 *
 * <p>
 * Never reference this interface directly. Always use {@link doan.quanlycanbo.portlet.service.quatrinhdinuocngoaiLocalServiceUtil} to access the quatrinhdinuocngoai local service.
 * </p>
 *
 * <p>
 * This is a local service. Methods of this service will not have security checks based on the propagated JAAS credentials because this service can only be accessed from within the same VM.
 * </p>
 *
 * @author Nguyen Tuan Vinh
 * @see doan.quanlycanbo.portlet.service.base.quatrinhdinuocngoaiLocalServiceBaseImpl
 * @see doan.quanlycanbo.portlet.service.quatrinhdinuocngoaiLocalServiceUtil
 */
public class quatrinhdinuocngoaiLocalServiceImpl
	extends quatrinhdinuocngoaiLocalServiceBaseImpl {
	
		public quatrinhdinuocngoai getByPrimaryKey(long maqtdnn) throws NoSuchquatrinhdinuocngoaiException, SystemException{
			return quatrinhdinuocngoaiPersistence.findByPrimaryKey(maqtdnn);
		}
	
		public List<quatrinhdinuocngoai> getAll() throws SystemException{
			return quatrinhdinuocngoaiPersistence.findAll();
		}
	
		public List<quatrinhdinuocngoai> getByHoso(long mahoso) throws SystemException{
			return quatrinhdinuocngoaiPersistence.findByHoSo(mahoso);
		}
	
		public quatrinhdinuocngoai addQTDNN(quatrinhdinuocngoai qtdnn1, long userId) throws SystemException{
			long maqtdnn = CounterLocalServiceUtil.increment(quatrinhdinuocngoai.class.getName());
			
			quatrinhdinuocngoai qtdnn2 = quatrinhdinuocngoaiPersistence.create(maqtdnn);		
			qtdnn2.setGroupId(qtdnn1.getGroupId());
			qtdnn2.setCompanyId(qtdnn1.getCompanyId());
			qtdnn2.setLanguageId(qtdnn1.getLanguageId());
			qtdnn2.setMahoso(qtdnn1.getMahoso());
			qtdnn2.setTungay(qtdnn1.getTungay());
			qtdnn2.setDenngay(qtdnn1.getDenngay());
			qtdnn2.setQuocgia(qtdnn1.getQuocgia());
			qtdnn2.setMucdich(qtdnn1.getMucdich());
			
			try {
				resourceLocalService.addResources(qtdnn1.getCompanyId(), qtdnn1.getGroupId(), userId, 
						quatrinhdinuocngoai.class.getName(), qtdnn2.getPrimaryKey(), false, true, true);
			} catch (PortalException e) {
				e.printStackTrace();
			}
			
			return quatrinhdinuocngoaiPersistence.update(qtdnn2, false);
		}
		
		public quatrinhdinuocngoai updateQTDNN(long maqtdnn,Date tungay, Date denngay, String quocgia, String mucdich) throws NoSuchdienbienhochamException, SystemException, NoSuchdienbienluongException, NoSuchquatrinhdinuocngoaiException{
			quatrinhdinuocngoai qtdnn = quatrinhdinuocngoaiPersistence.findByPrimaryKey(maqtdnn);
			qtdnn.setTungay(tungay);
			qtdnn.setDenngay(denngay);
			qtdnn.setQuocgia(quocgia);
			qtdnn.setMucdich(mucdich);
			return quatrinhdinuocngoaiPersistence.update(qtdnn, false);
		}
		
		public void deleteQTDNN(long maqtdnn) throws SystemException, PortalException{
			quatrinhdinuocngoai qtdnn = quatrinhdinuocngoaiPersistence.findByPrimaryKey(maqtdnn);
			deleteQTDNN(qtdnn);
		}
		
		public void deleteQTDNN(quatrinhdinuocngoai qtdnn) throws PortalException, SystemException{
			resourceLocalService.deleteResource(qtdnn.getCompanyId(), quatrinhdinuocngoai.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, qtdnn.getPrimaryKey());
			quatrinhdinuocngoaiPersistence.remove(qtdnn);
		}
}